﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.IO;

namespace OntoWPFSilverlight.Widget
{
    [OntoWPFSilverlight.Annotation.Widget("ButtonFileFolder")]
    public class ButtonFileFolder : CustomButton
    {
        //Xml.WidgetLocation widgetLocation = null;
        //Xml.WidgetSize widgetSize = null;
        //Xml.WidgetFont widgetFont = null;
        //Xml.Appearance appearance = null;
        //string widgetParent;
        //string type;
        
        public ButtonFileFolder() : base()
        {
            //System.Windows.Browser.HtmlPage.Window.Alert("BUTton costruttore");
            Build();
        }

        private void Build()
        {
            //System.Windows.Browser.HtmlPage.Window.Alert("BUTton dentro build");
            this.Click += new RoutedEventHandler(bOpenFileDialog_Click);
        }

        private void bOpenFileDialog_Click(object sender, RoutedEventArgs e)
        {
            // Create an instance of the open file dialog box.
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            // Set filter options and filter index.
            openFileDialog1.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;

            openFileDialog1.Multiselect = true;
            
            // Call the ShowDialog method to show the dialog box.
            bool? userClickedOK = openFileDialog1.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOK == true)
            {
                // Open the selected file to read.
                System.IO.Stream fileStream = openFileDialog1.File.OpenRead();
                string path = openFileDialog1.File.FullName;
                //using (System.IO.StreamReader reader = new System.IO.StreamReader(fileStream))
                //{
                //    // Read the first line from the file and write it the textbox.
                //    this.Tag = reader.ReadLine();
                //}
                fileStream.Close();
            }
        }





        #region IWidget Membri di

        //Xml.WidgetLocation Interfaces.IWidget.WidgetLocation
        //{
        //    get
        //    {
        //        //return widgetLocation == null ? new Xml.WidgetLocation(Int32.Parse(base.GetValue(LeftProperty).ToString()), Int32.Parse(base.GetValue(TopProperty).ToString()), "", "") : widgetLocation;
        //        return null;
        //    }
        //    set
        //    {
        //        System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter location");
        //        widgetLocation = value;
        //        Canvas.SetLeft(this, widgetLocation.X);
        //        Canvas.SetTop(this, widgetLocation.Y);
        //    }
        //}

        //Xml.WidgetSize Interfaces.IWidget.WidgetSize
        //{
        //    get
        //    {
        //        return widgetSize == null ? new Xml.WidgetSize(Int32.Parse(this.GetValue(WidthProperty).ToString()), Int32.Parse(this.GetValue(HeightProperty).ToString())) : widgetSize;
        //    }
        //    set
        //    {
        //        System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter size");
        //        widgetSize = value;
        //        this.Height = widgetSize.Height;
        //        this.Width = widgetSize.Width;
        //    }
        //}

        //Xml.WidgetFont Interfaces.IWidget.WidgetFont
        //{
        //    get
        //    {
        //        return widgetFont;
        //    }
        //    set
        //    {
        //        widgetFont = value;
        //    }
        //}

        //Xml.Appearance Interfaces.IWidget.Appearance
        //{
        //    get
        //    {
        //        return appearance == null ? new Xml.Appearance(base.GetValue(BackgroundProperty).ToString(), "", base.GetValue(CursorProperty).ToString()) : appearance;
        //    }
        //    set
        //    {
        //        System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter appareance");
        //        appearance = value;
        //        byte r, g, b;
        //        byte.TryParse(appearance.BackColor.Split(',')[0], out r);
        //        byte.TryParse(appearance.BackColor.Split(',')[1], out g);
        //        byte.TryParse(appearance.BackColor.Split(',')[2], out b);
        //        this.Background = new SolidColorBrush(Color.FromArgb(255, r, g, b));
        //    }
        //}

        //string Interfaces.IWidget.Name
        //{
        //    get
        //    {
        //        return this.Name;
        //    }
        //    set
        //    {
        //        System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter name "+ value);
        //        this.Name = value;
        //    }
        //}

        //string Interfaces.IWidget.WidgetParent
        //{
        //    get
        //    {
                
        //        return widgetParent == null ? base.Parent.ToString() : widgetParent;
        //    }
        //    set
        //    {
        //        System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter parent");
        //        widgetParent = value;
        //    }
        //}

        //string Interfaces.IWidget.Type
        //{
        //    get
        //    {
        //        return type == null ? base.GetType().ToString() : type;
        //    }
        //    set
        //    {
        //        System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter type");
        //        type = value;
        //    }
        //}

        //string Interfaces.IWidget.Text
        //{
        //    get
        //    {
        //        return Content == null ? base.Content.ToString() : Content.ToString();
        //    }
        //    set
        //    {
        //        System.Windows.Browser.HtmlPage.Window.Alert("BUTton setter content" + value);
        //        this.Content = value;
        //    }
        //}


        #endregion
    }
}
